package be.dch.srtm2osm;

import java.util.List;

import uk.me.parabola.imgfmt.Utils;
import uk.me.parabola.splitter.Area;
import uk.me.parabola.splitter.UnknownFeatureException;
import crosby.binary.BinaryParser;
import crosby.binary.Osmformat;
import crosby.binary.Osmformat.DenseNodes;
import crosby.binary.Osmformat.Node;
import crosby.binary.Osmformat.Relation;
import crosby.binary.Osmformat.Way;

public class BinaryMapParserArea extends BinaryParser {
    // How many elements to process before displaying a status update

    private Area area;

    BinaryMapParserArea() {
    }

    public void complete() {
	// End of map is sent when all input files are processed.
	// So do nothing.
    }

    @Override
    public void parse(final Osmformat.HeaderBlock block) {

	for (final String s : block.getRequiredFeaturesList()) {
	    if (s.equals("OsmSchema-V0.6")) {
		continue; // OK.
	    }
	    if (s.equals("DenseNodes")) {
		continue; // OK.
	    }
	    throw new UnknownFeatureException(s);
	}

	if (block.hasBbox()) {
	    final double multiplier = .000000001;
	    final double rightf = block.getBbox().getRight() * multiplier;
	    final double leftf = block.getBbox().getLeft() * multiplier;
	    final double topf = block.getBbox().getTop() * multiplier;
	    final double bottomf = block.getBbox().getBottom() * multiplier;

	    System.out.println("Bounding box " + leftf + " " + bottomf + " " + rightf + " " + topf);
	    // srtm2osm.exe -bounds1 57.71690 4.01368 71.19163 31.14427 -cat 400
	    // 100 -large -corrxy 0.0005 0.0006 -o no.srtm.osm

	    // strm2osmCommand = "srtm2osm.exe -bounds " + bottomf + " " + leftf
	    // + " " + topf + " " + rightf +
	    // "-cat 400 100 -large -corrxy 0.005 0.0006 -o " + "" +
	    // ".srtm.osm";

	    this.area = new Area(Utils.toMapUnit(bottomf), Utils.toMapUnit(leftf), Utils.toMapUnit(topf), Utils.toMapUnit(rightf));
	    throw new RuntimeException("done.");
	}
    }

    public Area getArea() {
	return this.area;
    }

    @Override
    protected void parseRelations(List<Relation> rels) {
	// TODO Auto-generated method stub
	
    }

    @Override
    protected void parseDense(DenseNodes nodes) {
	// TODO Auto-generated method stub
	
    }

    @Override
    protected void parseNodes(List<Node> nodes) {
	// TODO Auto-generated method stub
	
    }

    @Override
    protected void parseWays(List<Way> ways) {
	// TODO Auto-generated method stub
	
    }

}
